package com.qilinreal.app;

import java.io.*;

import java.awt.image.*;
import javax.imageio.ImageIO;

public class Image2Point {
	public static void main(String[] args) throws Exception {
		File file = new File("./image.bmp");
		BufferedImage bi = ImageIO.read(file);

		save(bi);
	}

	static void save(BufferedImage bi) throws Exception {
		File file = new File("points.in");
		FileOutputStream fos = new FileOutputStream(file);
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
		int width = bi.getWidth();
		int height = bi.getHeight();
		for(int i=0; i<height; i++) {
			for(int j=0; j<width; j++) {
				int rgb = bi.getRGB(j, i);
				if((rgb&0xffffff) != 0xffffff) {
					bw.write(String.format("%d,%d", j, i));
					bw.newLine();
				}
			}
		}
		bw.flush();
		bw.close();
		fos.close();
	}
}